// pages/adminNotifications/adminNotifications.js
const auth = require('../../utils/auth')

Page({
  data: {
    loading: false
  },

  onLoad() {
    this.checkAdminStatus()
  },

  onShow() {
    this.checkAdminStatus()
  },

  // 检查管理员状态
  checkAdminStatus() {
    const user = auth.getCurrentUser()
    
    if (!user) {
      wx.showModal({
        title: '需要登录',
        content: '请先进行身份验证',
        showCancel: false,
        success: () => {
          wx.reLaunch({
            url: '/pages/home/home'
          })
        }
      })
      return
    }

    if (user.role !== 'admin') {
      wx.showModal({
        title: '权限不足',
        content: '只有管理员可以访问此页面',
        showCancel: false,
        success: () => {
          wx.navigateBack()
        }
      })
      return
    }
  },

  // 返回首页
  goHome() {
    wx.switchTab({
      url: '/pages/home/home'
    })
  }
})